/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef NAS_SNAPSHOT_COMMON_JOB_H
#define NAS_SNAPSHOT_COMMON_JOB_H

#include "BasicJob.h"
#include "device_access/dorado/DoradoNas.h"
#include "device_access/fusionstorage/FusionStorageNas.h"
#include "client/ClientInvoke.h"
#include "nas_share/common/HetroCommonStructs.h"

struct DeviceInfo {
    std::string username;
    std::string password;
    std::string port;
    std::string fileSystemName;
    std::string fileSystemId;
    std::string ipList;
};

struct ProtectObjectExtendInfo {
    std::string tenantName {};
    std::string fileSystemId {};
    std::string usedCapacity {};
    std::string onlineStatus {};
    std::string tenantId {};
    std::string capacity {};

    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(tenantName, tenantName)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemId, fileSystemId)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(usedCapacity, usedCapacity)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(onlineStatus, onlineStatus)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(tenantId, tenantId)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(capacity, capacity)
    END_SERIAL_MEMEBER
};

struct TargetObjectExtendInfo {
    std::string tenantName {};
    std::string fileSystemId {};
    std::string usedCapacity {};
    std::string onlineStatus {};
    std::string tenantId {};
    std::string capacity {};

    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(tenantName, tenantName)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemId, fileSystemId)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(usedCapacity, usedCapacity)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(onlineStatus, onlineStatus)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(tenantId, tenantId)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(capacity, capacity)
    END_SERIAL_MEMEBER
};

class SnapshotCommon : public BasicJob {
public:
    SnapshotCommon() {};
    virtual ~SnapshotCommon();
    virtual int PrerequisiteJob() = 0;
    virtual int GenerateSubJob() = 0;
    virtual int ExecuteSubJob() = 0;
    virtual int PostJob() = 0;

protected:
    DeviceInfo m_deviceInfo;
    std::shared_ptr<Module::ControlDevice> m_localDeviceController = nullptr;
    AppProtect::JobResult::type m_backupJobResult {AppProtect::JobResult::type::SUCCESS};
    uint64_t m_curProcess = 0;
    std::string m_subjobId;
    std::string m_jobId;
    std::atomic<int> m_jobProgress {0};
    std::atomic<double> m_dataSize {0.0};
    std::string m_jobCtrlPhase {}; // job phase
    std::string m_vstoreId;
    const std::string EMPTY_LABEL = "";
    /* protected NAS Host information */
    ProtectedNasHost m_nasHost {};
    /* Protected NAS Share Information */
    ProtectedNasShare m_nasShare {};

protected:
    int InitDeviceInfo();
    int FillDeviceInfo(Module::ControlDeviceInfo &localDeviceInfo);
    Module::STORAGE_ENUM GetVendorType(const std::string& inputVendorStr) const;
    void ReportJobDetails(const std::string& label,
        const JobLogLevel::type &level, const SubJobStatus::type sts, int progress);
    std::string FormatSnapshotName(const std::string& snapshotName);
};

#endif